const Bridge = (<any>window).YHAuthorize;
const success_code = "0";
import { Toast } from "vant";

export default {
    // 获取设备信息
    DeviceInfo() {
        return new Promise((resolve, reject) => {
            let params = { param: "设备信息——Device_Environment" };
            Bridge.callHandler("Device_Environment", params, (resp: any) => {
                if (resp.code == "1001") {
                    resolve(resp);
                }
            });
        });
    },

    // 设置请求头
    SetAutoHeader(headerObj: object) {
        return new Promise((resolve, reject) => {
            let params = { param: "设备信息——Device_Environment" };
            Bridge.callHandler("setAutoHeader", headerObj, (resp: any) => {
                if (resp.code == "1001") {
                    resolve(resp);
                }
            });
        });
    },

    // 图片选择
    ImagePicker(type: String, fileType: String) {
        let params = {
            type: type, // 系统相机
            fileType: fileType,
            fileFolderName: "/sdcard/uppo",
            imageName: `${Date.now()}.jpg`,
            imageSize: `${500 * 1024}`
        };
        return new Promise((resolve, reject) => {
            Bridge.callHandler("phoneImagePicker", params, (resp: any) => {
                console.log("back", resp);
                resp = JSON.parse(resp);
                if (resp.code == "1001") {
                    resolve(resp.data);
                }
            });
        });
    },

    // 通用
    GetSDKData(key: String, data: Object) {
        console.log("here");
        let params = { key: key, data: data };
        return new Promise((resolve, reject) => {
            Bridge.callHandler("getSDKData", params, (resp: any) => {
                resp = JSON.parse(resp);
                console.warn("back:-------------");
                if (resp.code == "1001") {
                    console.log(resp.data);
                    resolve(resp.data);
                } else {
                    Toast(resp.message);
                    reject(resp);
                }
            });
        });
    }
};
